package com.devenv.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/**
 * 用户登录响应DTO
 * <p>
 * 用于返回登录成功后的认证信息和用户数据
 * </p>
 * 
 * @author DevEnv OpenSource Team
 * @version 1.0.0
 * @since 1.0.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginResponse {
    private String token;
    private String tokenType = "Bearer";
    private Long expiresIn;
    private UserDTO user;
    private boolean success = true;
    private String message = "登录成功";

    public LoginResponse(String token, Long expiresIn, UserDTO user) {
        this.token = token;
        this.expiresIn = expiresIn;
        this.user = user;
        this.success = true;
        this.message = "登录成功";
    }

    /**
     * 创建成功响应
     */
    public static LoginResponse success(String token, Long expiresIn, UserDTO user) {
        return new LoginResponse(token, expiresIn, user);
    }

    /**
     * 创建成功响应（带消息）
     */
    public static LoginResponse success(String token, Long expiresIn, UserDTO user, String message) {
        LoginResponse response = new LoginResponse(token, expiresIn, user);
        response.setMessage(message);
        return response;
    }

    /**
     * 创建失败响应
     */
    public static LoginResponse failure(String message) {
        LoginResponse response = new LoginResponse();
        response.setSuccess(false);
        response.setMessage(message);
        return response;
    }

    /**
     * 获取完整的Authorization头
     */
    public String getAuthorizationHeader() {
        return tokenType + " " + token;
    }

    /**
     * 检查token是否即将过期（小于5分钟）
     */
    public boolean isTokenNearExpiry() {
        if (expiresIn == null) return false;
        return expiresIn < 300000; // 5分钟 = 300000毫秒
    }
}
